package com.example.question.dfs;

import java.util.ArrayList;
import java.util.List;

/**
 * @Date 2023-07-15
 * @Author Jonathan
 */
public class Code01_589 {


    public List<Integer> preorder(Node root) {
        if (root == null) {
            return ans;
        }
        preOrder(root);
        return ans;
    }

    List<Integer> ans = new ArrayList<>();

    public void preOrder(Node node) {
        if (node == null) {
            return;
        }
        ans.add(node.val);
        for (Node child : node.children) {
            preOrder(child);
        }

    }


    static class Node {
        public int val;
        public List<Node> children;

        public Node() {
        }

        public Node(int _val) {
            val = _val;
        }

        public Node(int _val, List<Node> _children) {
            val = _val;
            children = _children;
        }
    }
}
